import multiprocessing as mp
import threading as td
import time

def job(q):
    res = 0
    for i in range(10000000):
        res += i + i**2 + i**3
    q.put(res)

def multicore():
    q = mp.Queue()
    p1 = mp.Process(target=job,args=(q,))
    p2 = mp.Process(target=job,args=(q,))
    p1.start()
    p2.start()
    p1.join()
    p2.join()
    res1 = q.get()
    res2 = q.get()
    print("multiProc: "+str(res1+res2))

def normal():
    res = 0
    for _ in range(2):
        for i in range(10000000):
            res += i + i**2 +i**3
    print("normal: "+str(res))

def multiThread():
    q = mp.Queue()
    t1 = td.Thread(target=job,args=(q,))
    t2 = td.Thread(target=job,args=(q,))
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    res1= q.get()
    res2 = q.get()
    print("multiThread: "+str(res1+res2))

if __name__ == '__main__':
    t1 = time.time()
    normal()
    t2 = time.time()
    print(t2-t1)

    t3 = time.time()
    multiThread()
    t4 = time.time()
    print(t4-t3)

    t5 = time.time()
    multicore()
    t6 = time.time()
    print(t6-t5)